﻿// -----------------------------
// Copyright © Kodi Studios 2012
// -----------------------------

using System.Xml;

namespace Kodi.Picturethrill
{
    class XmlUtilities
    {
        public static void AddChild(XmlNode xmlNode, string nodeName, string nodeValue)
        {
            XmlNode childNode = xmlNode.OwnerDocument.CreateElement(nodeName);
            childNode.InnerText = nodeValue;
            xmlNode.AppendChild(childNode);
        }

        public static void AddChild(XmlNode xmlNode, string nodeName, bool nodeValue)
        {
            AddChild(xmlNode, nodeName, nodeValue.ToString());
        }

        public static bool GetValue(XmlNode xmlNode, string nodeName, bool defaultValue)
        {
            bool returnValue = defaultValue;
            XmlElement childNode = (XmlElement)xmlNode.SelectSingleNode(nodeName);
            if (childNode != null)
            {
                returnValue = bool.Parse(childNode.InnerText);
            }

            return returnValue;
        }

        public static string GetValue(XmlNode xmlNode, string nodeName, string defaultValue)
        {
            string returnValue = defaultValue;
            XmlElement childNode = (XmlElement)xmlNode.SelectSingleNode(nodeName);
            if (childNode != null)
            {
                returnValue = childNode.InnerText;
            }

            return returnValue;
        }
    }
}
